﻿using Clancy.Ui.ViewModels;
using Ninject;
using ReactiveUI;
using System;

namespace Clancy.Ui
{
    public class ViewModelLocator : IViewModelFactory
    {
        protected readonly IKernel Kernel;

        public ViewModelLocator()
            : this(new StandardKernel())
        {
        }

        public ViewModelLocator(IKernel kernel)
        {
            Kernel = kernel;
            kernel.Bind<IViewModelFactory>().ToConstant(this);
        }

        public MainWindowViewModel MainWindowViewModel
        {
            get { return Kernel.Get<MainWindowViewModel>(); }
        }

        public ZoneEditorViewModel ZoneEditorViewModel
        {
            get { return Kernel.Get<ZoneEditorViewModel>(); }
        }

        public IViewModel GetViewModel(Type viewModelType)
        {
            return Kernel.Get(viewModelType) as IViewModel;
        }

        public T GetViewModel<T>() where T : IViewModel
        {
            return Kernel.Get<T>();
        }
    }

    public interface IViewModelFactory
    {
        IViewModel GetViewModel(Type viewModelType);

        T GetViewModel<T>() where T : IViewModel;
    }

    public interface IViewModel
    {
    }
}